//
//  MakefirendsReleaseOneCell.m
//  cityStar
//
//  Created by joyban on 15-1-26.
//  Copyright (c) 2015年 tiny. All rights reserved.
//

#import "MakefirendsReleaseOneCell.h"
#import "selectDistrict.h"

@implementation MakefirendsReleaseOneCell

+(CGFloat)heightOfTableCell
{
    return 352;
}

- (void)awakeFromNib {
    
    self.arrayName = [[NSArray alloc]init];
    self.arrayid = [[NSArray alloc]init];
    
    self.ageText.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.ageText.layer.borderWidth = 0.5f;
    
    self.arrayName  = [selectDistrict shardDistrictInfo].DistrictNameArray;
    self.arrayid =[selectDistrict shardDistrictInfo].DistrictIdArray;
    self.marriageType = @"0";
    self.strAddressID = [NSString stringWithFormat:@"%@",self.arrayid[0]];

    self.titleText.delegate = self;
    self.ageText.delegate = self;
    self.addressText.delegate = self;
    self.ContactTetx.delegate = self;
    self.ContactTelphoneText.delegate = self;
    self.NowAddressText.delegate = self;
    self.MarriageText.delegate = self;
    
    self.segmengIndex = 0;
    
    UIPickerView *typePickerView = [[UIPickerView alloc]init];
    typePickerView.delegate = self;
    typePickerView.tag = 0;
    self.MarriageText.inputView = typePickerView;
    
    UIPickerView *addressPickerView = [[UIPickerView alloc]init];
    addressPickerView.delegate = self;
    addressPickerView.tag = 1;
    self.NowAddressText.inputView = addressPickerView;
    
    UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 30)];
    [topView setBarStyle:UIBarStyleDefault];
    
    UIBarButtonItem * btnSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    
    UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(dismissKeyBoard)];
    
    NSArray * buttonsArray = [NSArray arrayWithObjects:btnSpace,doneButton,nil];
    
    [topView setItems:buttonsArray];
    [self.MarriageText setInputAccessoryView:topView];
    [self.NowAddressText setInputAccessoryView:topView];
    
}

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    switch (textField.tag) {
        case 4:
            textField.text = @"未婚";
            break;
        case 6:
            textField.text = @"市辖区";
            break;
            
        default:
            break;
    }
}

-(void)dismissKeyBoard
{
    [self.MarriageText resignFirstResponder];
    [self.NowAddressText resignFirstResponder];
}

#pragma mark - actions
- (IBAction)selectSeg_Tuch:(UISegmentedControl *)sender {
    self.segmengIndex = sender.selectedSegmentIndex;
}

#pragma mark - pickerViewDelegate
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (pickerView.tag == 0) {
        return 4;
    }else{
        return self.arrayName.count;
    }
}

-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (pickerView.tag == 0) {
        if (row == 0) {
            return @"未婚";
        }else if (row == 1){
            return @"已婚";
        }else if (row == 2){
            return @"离异";
        }else
        {
            return @"丧偶";
        }
    }else{
        return self.arrayName[row];
    }
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (pickerView.tag == 0) {
        if (row == 0) {
            self.MarriageText.text = @"未婚";
            self.marriageType = @"0";
        }else if (row == 1){
            self.MarriageText.text = @"已婚";
            self.marriageType = @"1";
        }else if (row == 2){
            self.MarriageText.text = @"已婚离异";
            self.marriageType = @"2";
        }else{
            self.MarriageText.text = @"丧偶";
            self.marriageType = @"3";
        }
    }else {
        NSString *strname = [NSString stringWithFormat:@"%@",self.arrayName[row]];
        self.strAddressID = [NSString stringWithFormat:@"%@",self.arrayid[row]];
        self.NowAddressText.text = strname;
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

@end
